package rcp.iphex2.ui.projectexplorer.commandhandler;

import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import rcp.iphex2.model.Project;
import rcp.iphex2.model.ProjectEntry;


public class DeleteProjectEntryHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
		List<Object> structuredSelectionList = selection.toList();
		for (Object object : structuredSelectionList) {
			if (object instanceof ProjectEntry) {
				ProjectEntry projectEntry = (ProjectEntry) object;
				Project project = projectEntry.getRootProject();
				project.removeProjectEntry(projectEntry);
				System.out.println("Removing: " + projectEntry.getMeasurementFileName());
			}
		}

		return null;
	}

}
